﻿/********************************************************************
FileName    :   Bll_OS.cs
CreateTime  :   2020-09-26 11:44:21
BaseClass   :   Bll_OS
FileType    :   .cs
Author      :  minjie
*********************************************************************/


using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;

using System.Data;
namespace OS.DAL
{
    /// <summary>
    /// Dal_jbxx_qydaH的摘要说明。
    /// </summary>
    public partial class Dal_view_Spda
    {

        public bool Exists(string spbh)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from view_Spda");
            strSql.Append(" where  spbh=@spbh ");
            SqlParameter[] parameters = { new SqlParameter("@spbh", SqlDbType.VarChar, 50) };
            parameters[0].Value = spbh;


            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary> 
        /// 得到一个对象实体 
        /// </summary> 
        public view_Spda_Entity GetModel(string spbh)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1   djlsh,spbh,spmc,tmh,lsj,pfj,jj,flmc,tpdz,kcsl,xgsj,djsj   ");
            strSql.Append(" from view_Spda  where spbh='" + spbh + "'");
            view_Spda_Entity model = new view_Spda_Entity();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            DataTable dt = ds.Tables[0];
            return DataTableToEntity(dt);
        }
        /// <summary> 
        /// 将数据集(DataTable)转换 对象 jbxx_qydaH_Entity
        /// 创建人：minjie 
        /// 创建时间:2019-02-18 02:05:58 
        /// </summary> 
        public view_Spda_Entity DataTableToEntity(DataTable dt)
        {
            view_Spda_Entity model = new view_Spda_Entity();
            if (dt != null && dt.Rows.Count > 0)
            {

                if (dt.Rows[0]["DjLsh"] != null && dt.Rows[0]["DjLsh"].ToString() != "")
                    model.DjLsh = int.Parse(dt.Rows[0]["DjLsh"].ToString());

                model.spbh = dt.Rows[0]["spbh"].ToString();
                model.spmc = dt.Rows[0]["spmc"].ToString();
                model.tmh = dt.Rows[0]["tmh"].ToString();
                model.flmc = dt.Rows[0]["flmc"].ToString();
                model.tpdz = dt.Rows[0]["tpdz"].ToString();

                if (dt.Rows[0]["lsj"] != null && dt.Rows[0]["lsj"].ToString() != "")
                    model.lsj = decimal.Parse(dt.Rows[0]["lsj"].ToString());


                if (dt.Rows[0]["pfj"] != null && dt.Rows[0]["pfj"].ToString() != "")
                    model.pfj = decimal.Parse(dt.Rows[0]["pfj"].ToString());


                if (dt.Rows[0]["jj"] != null && dt.Rows[0]["jj"].ToString() != "")
                    model.jj = decimal.Parse(dt.Rows[0]["jj"].ToString());

                if (dt.Rows[0]["kcsl"] != null && dt.Rows[0]["kcsl"].ToString() != "")
                    model.kcsl = decimal.Parse(dt.Rows[0]["kcsl"].ToString());
                //,
                if (dt.Rows[0]["xgsj"] != null && dt.Rows[0]["xgsj"].ToString() != "")
                    model.xgsj = DateTime.Parse(dt.Rows[0]["xgsj"].ToString());

         if (dt.Rows[0]["djsj"] != null && dt.Rows[0]["djsj"].ToString() != "")
                    model.djsj = DateTime.Parse(dt.Rows[0]["djsj"].ToString());




                return model;
            }
            else
            {
                return null;
            }
        }



        /// <summary> 
        /// 执行sql语句  
        /// </summary> 
        public string GetSingle(string sql)
        {
            object obj = DbHelperSQL.GetSingle(sql);
            if (obj != null)
            {
                return obj.ToString();
            }
            else
                return "";
        }
        /// <summary> 
        /// 获得记录条数 
        /// </summary> 
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) ");
            strSql.Append(" FROM view_Spda ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj != null && obj.ToString() != "")
                return Convert.ToInt32(obj);
            else
                return 0;
        }
        /// <summary> 
        /// 批量处理  
        /// </summary> 
        public int ExecuteSqlTran(List<string> ls, ref string error)
        {
            return DbHelperSQL.ExecuteSqlTran(ls, ref error);
        }
        /// <summary> 
        /// 分页获取数据列表 
        /// </summary> 
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by " + orderby);
            }
            else
            {
                strSql.Append("order by T.DjLsh desc");
            }
            strSql.Append(")AS Row, T.*  from view_Spda  T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM view_Spda ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary> 
        /// 直接执行sql语句 
        /// </summary> 
        public int ExecuteSql(string sql)
        {
            return DbHelperSQL.ExecuteSql(sql);
        }
        /// <summary> 
        /// 直接执行sql语句 
        /// </summary> 
        public DataTable ExecuteDt(string sql)
        {
            return DbHelperSQL.ExecuteDt(sql);
        }


    }
}
